#ifndef ___EVENTPP_TCP_ACCEPTOR_H_
#define ___EVENTPP_TCP_ACCEPTOR_H_

struct evconnlistener;

namespace eventpp
{
  class net_base;
  class tcp_handler;

	class tcp_acceptor_config 
	{
	public:
		uint32_t				ip;   // network order
		uint16_t				port;

		tcp_acceptor_config () 
		{
			reset();
		}

		void reset();
	};

	class tcp_acceptor
	{
	private:
		net_base &		base_;
		tcp_acceptor_config *	config_;
		tcp_handler *			handler_;
		struct evconnlistener *	listener_;

	public:
		tcp_acceptor( net_base & base, tcp_acceptor_config * config, tcp_handler * handler );
		~tcp_acceptor();

		net_base &		base() const { return base_; }
		tcp_acceptor_config *	config() const { return config_; }
		tcp_handler *			handler() const { return handler_; }

		void start();
		void close();

	private:
		static void acceptcb(evconnlistener *serv, int sock, sockaddr *sa, int sa_len, void *arg);
	};

}
#endif
